package com.erpanderp.wam.usm.model.service.user;

import java.util.List;

import org.hibernate.FlushMode;
import org.hibernate.Session;

import com.erpanderp.wam.tm.model.entity.RecruitmentProfile;
import com.erpanderp.wam.usm.model.entity.user.EmployeePhoto;
import com.erpanderp.wam.util.HibernateUtil;

public class EmployeePhotoDAO {

	public EmployeePhoto uploadEmployeeImages(EmployeePhoto uploadEmployeeImages) {
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.AUTO);
			session.save(uploadEmployeeImages);
			session.getTransaction().commit();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return uploadEmployeeImages;
	}

	public boolean saveEmployeeImages(List<EmployeePhoto> employeeImageList) {
		boolean recruitmentProfileCreated = false;
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.AUTO);

			for (EmployeePhoto uploadImage : employeeImageList) {
				session.saveOrUpdate(uploadImage);
			}
			session.getTransaction().commit();
			recruitmentProfileCreated = true;
		} catch (Exception e) {
			e.printStackTrace();
			return recruitmentProfileCreated;

		}
		return recruitmentProfileCreated;
	}
	
	public boolean saveEmployeePhoto(EmployeePhoto employeePhoto){
		boolean recruitmentProfileCreated = false;
		try{
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.AUTO);
		
			session.saveOrUpdate(employeePhoto);
			session.getTransaction().commit();
			recruitmentProfileCreated = true;
		}catch(Exception e){
			e.printStackTrace();
			return recruitmentProfileCreated;
			
		}
		return recruitmentProfileCreated;
	}	
}
